package com.liubo.ssepro.Controller;

import com.liubo.ssepro.Entity.TokenEntity;
import com.liubo.ssepro.Entity.ProposalEntity;
import com.liubo.ssepro.Entity.UserEntity;
import com.liubo.ssepro.Repository.TokenRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

import static javafx.scene.input.KeyCode.T;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    TokenRepository tokenRepository;
    /*
    检查用户已经登录
     */
    public TokenEntity if_hasLogin(String token){
        TokenEntity tokenEntity = null;
        //tokenEntity = tokenRepository.findByMaptoken(token);
        Date last = tokenEntity.getSuat();
        Date now = new Date();
        long JG = last.getTime() - now.getTime();
        JG=JG/(60*60*1000);
        if(JG>15){
            return null;
        }
        else{
            tokenEntity.setSuat(new Date());
            return tokenEntity;
        }
    }
    /*
        显示功能页
     */
  /*  @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String disHome( ){
        return "1";
    }*/
    /*EDIT  编辑功能
     *
     */
    //edit get
    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public String getEdit(HttpServletRequest request){

        return "l";
    }
    //edit post
   /* @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public String getEdit(UserEntity userEntity){
        return "l";
    }*/
    /*
        编写提案
     */
    //proposal read{id}
  /*  @RequestMapping(value = "/proposal/read/{id}", method = RequestMethod.POST)
    public String getEdit(@PathVariable("id") Integer id){

        return "l";
    }*/
    //proposal/create
    @RequestMapping(value = "/proposal/create", method = RequestMethod.POST)
    public String createProposal(HttpServletRequest request){
        String title = request.getParameter("title");
        String content = request.getParameter("content");
        Date createat =new Date();

        ProposalEntity proposalEntity = new ProposalEntity();
        proposalEntity.setTitle(title);
        proposalEntity.setContent(content);
        proposalEntity.setCreatat(createat);
        proposalEntity.setStatus(0);
        return "create";
    }
    //




}
